//
//  AppDelegate+UMeng.m
//  ZPrograme
//
//  Created by 周成龙 on 16/6/16.
//  Copyright © 2016年 none. All rights reserved.
//

#import "AppDelegate+UMeng.h"

#import "UMessage.h"
#import "UMSocial.h"
#import "UMSocialWechatHandler.h"
#import "UMSocialQQHandler.h"
#import "UMSocialSinaSSOHandler.h"

#import "VDJConstant.h"

@implementation AppDelegate (UMeng)

- (void)setUMengShareAppkey
{
    /** 友盟分享
     设置微信AppId和url地址
     @param appKey 友盟appKey
     @param app_Id 微信应用Id
     @param app_Secret 微信应用secret
     @param url 微信消息分享网页类型的url地址
     */
    [UMSocialData setAppKey:@"569e062467e58e9398000e74"];
    //设置微信AppId、appSecret，分享url
    NSString *strURL = @"http://www.umeng.com/social";
    // 微信 和 朋友圈
    [UMSocialWechatHandler setWXAppId:@"wx79e664dca32c12c8" appSecret:@"c83ddc493ee2773bb26af9b4d2dfb2fe" url:strURL];
    // QQ 和 QZone
    [UMSocialQQHandler setQQWithAppId:@"1104900306" appKey:@"l7yLDeZ6M8PBYfHM" url:strURL];
    
    // 新浪微博
    //第一个参数为新浪appkey,第二个参数为新浪secret，第三个参数是新浪微博回调地址，这里必须要和你在新浪微博后台设置的回调地址一致。
    [UMSocialSinaSSOHandler openNewSinaSSOWithAppKey:@"3921700954"
                                              secret:@"04b48b094faeb16683c32669824ebdad"
                                         RedirectURL:@"http://sns.whalecloud.com/sina2/callback"];
    
    /*
     微信好友 UMShareToWechatSession
     微信朋友圈 UMShareToWechatTimeline
     QQ空间 UMShareToQzone
     手机QQ UMShareToQQ
     新浪微博 UMShareToSina
     */
    [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToWechatSession, UMShareToWechatTimeline, UMShareToQQ, UMShareToQzone, UMShareToSina]];
}

- (void)pushMessagedidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //set AppKey and LaunchOptions
    [UMessage startWithAppkey:@"5624a5fa67e58eea76003858" launchOptions:launchOptions];
    
    if (IOS8orLater) {
        //register remoteNotification types
        UIMutableUserNotificationAction *action1 = [[UIMutableUserNotificationAction alloc] init];
        action1.identifier = @"action1_identifier";
        action1.title=@"Accept";
        action1.activationMode = UIUserNotificationActivationModeForeground;//当点击的时候启动程序
        
        UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init];  //第二按钮
        action2.identifier = @"action2_identifier";
        action2.title = @"Reject";
        action2.activationMode = UIUserNotificationActivationModeBackground;//当点击的时候不启动程序，在后台处理
        action2.authenticationRequired = YES;//需要解锁才能处理，如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略；
        action2.destructive = YES;
        
        UIMutableUserNotificationCategory *actionCategory = [[UIMutableUserNotificationCategory alloc] init];
        actionCategory.identifier = @"category1";//这组动作的唯一标示
        [actionCategory setActions:@[action1,action2] forContext:(UIUserNotificationActionContextDefault)];
        
        NSSet *categories = [NSSet setWithObject:actionCategory];
        //如果默认使用角标，文字和声音全部打开，请用下面的方法
        [UMessage registerForRemoteNotifications:categories];
        
        //如果对角标，文字和声音的取舍，请用下面的方法
//        UIRemoteNotificationType types7 = UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;
//        UIUserNotificationType types8 = UIUserNotificationTypeAlert|UIUserNotificationTypeSound|UIUserNotificationTypeBadge;
//        [UMessage registerForRemoteNotifications:categories withTypesForIos7:types7 withTypesForIos8:types8];
    }else {
        
        UIUserNotificationCategory *actionCategory = [[UIUserNotificationCategory alloc] init];
        NSSet *categories = [NSSet setWithObject:actionCategory];
        [UMessage registerForRemoteNotifications:categories];
    }
    //for log
    [UMessage setLogEnabled:YES];
}

@end








